//Source file: D:\\test\\com\\ce\\pms\\house\\model\\FlatDomain.java

package com.ce.pms.house.model;

import java.math.BigDecimal;

import javax.persistence.*;

import com.ce.pms.common.model.SysInfo;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.service.IImageService;
import com.ce.pms.house.vo.ImageVO;

@Entity
@Table(name = "CS_FLAT")
@PrimaryKeyJoinColumn(name = "FLAT_ID")
public class FlatDomain extends HouseDomain {

	/**
	 * 单元 检索策略:lazy=true
	 */
	@ManyToOne
	@JoinColumn(name = "HOUSE_GRP_ID")
	private HouseGrp houseGrp;

	/**
	 * 楼层
	 */
	@Column(name = "STOREY_NUMBER", nullable = false)
	private Integer floor;

	/**
	 * 效果图 检索策略:lazy=false
	 */
	@OneToOne(cascade={CascadeType.REMOVE},fetch=FetchType.EAGER)
	@JoinColumn(name="ICHNOGRAPHY_ID")
	private ImageDomain ichnography;

	/**
	 * 管线图 检索策略:lazy=false
	 */
	@OneToOne(cascade={CascadeType.REMOVE},fetch=FetchType.EAGER)
	@JoinColumn(name="PIPELINE_IMAGE_ID")
	private ImageDomain pipelineImage;

	/**
	 * 交房标准
	 */
	@ManyToOne
	@JoinColumn(name = "SYS_REF_ID1", nullable = false)
	private SysrefcodeDO deliveryLimitation;

	/**
	 * 朝向
	 */
//	@ManyToOne
//	@JoinColumn(name = "SYS_REF_ID2", nullable = true)
	@Column(name="DIRECTION",length=100)
	private String direction;

	/**
	 * @roseuid 484F3FA60196
	 */
	public FlatDomain() {
	}

	/**
	 * 功能描述: 设置图片服务
	 *
	 * @author 付湘辉
	 * Created on:2008-7-1
	 *
	 * 修改原因：
	 * @param imageService the 图片服务 to set
	 */
	public void setImageService(IImageService imageService) {
		this.imageService = imageService;
	}

	/**
	 * mini constructor
	 *
	 * @param houseNumber
	 *            房号
	 * @param buildSize
	 *            建筑面积
	 * @param innerSize
	 *            套内面积
	 * @param publicSize
	 *            公共面积
	 * @param status
	 *            房屋状态
	 * @param remark
	 *            备注
	 * @param floor
	 *            楼层
	 * @param deliveryLimitation
	 *            交房标准
	 * @param sysInfo
	 *            系统信息
	 */
	public FlatDomain(String houseNumber, BigDecimal buildSize,
			BigDecimal innerSize, BigDecimal publicSize, SysrefcodeDO status,
			String remark, Integer floor, SysrefcodeDO deliveryLimitation,
			SysInfo sysInfo) {
		super(houseNumber, buildSize, innerSize, publicSize, status, remark,
				SysrefcodeDO.CONSTANTS_DIGITAL_ZERO, sysInfo);
		this.floor = floor;
		this.deliveryLimitation = deliveryLimitation;
	}
	/**************************************************
	 * Accessors and Modifiers
	 **************************************************/
	public SysrefcodeDO getDeliveryLimitation() {
		return deliveryLimitation;
	}

	public void setDeliveryLimitation(SysrefcodeDO deliveryLimitation) {
		this.deliveryLimitation = deliveryLimitation;
	}

	public String getDirection() {
		return direction;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public Integer getFloor() {
		return floor;
	}

	public void setFloor(Integer floor) {
		this.floor = floor;
	}

	public HouseGrp getHouseGrp() {
		return houseGrp;
	}

	public void setHouseGrp(HouseGrp houseGrp) {
		this.houseGrp = houseGrp;
	}

	/**
	 * 图片服务
	 */
	@Transient
	private IImageService imageService;

	public ImageDomain addImage(ImageVO image){
		Long imageId = this.imageService.addImage(image);
		return null;
	}

	public ImageDomain getIchnography() {
		return ichnography;
	}

	public void setIchnography(ImageDomain ichnography) {
		this.ichnography = ichnography;
	}

	public ImageDomain getPipelineImage() {
		return pipelineImage;
	}

	public void setPipelineImage(ImageDomain pipelineImage) {
		this.pipelineImage = pipelineImage;
	}

	/**
	 *
	 * 功能描述: 判断必填项是否有值
	 *
	 * @author 付湘辉
	 * Created on:2008-7-11
	 *
	 * 修改原因：
	 * @return void 返回结果
	 */
	@Override
	public void checkRequiredField(){
		super.checkRequiredField();
		if (this.floor == null || this.deliveryLimitation == null) {
			throw new BusinessException("common:mustFill_null_exception",
					BusinessException.WARNING);
		}
	}

	/**
	 * 功能描述: 检查面积规则 <br>
	 *
	 *
	 * Create author:付湘辉 <br>
	 * Create on:2008-7-28  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void checkHouseDimensionRole(){
		if (SysrefcodeDO.CONSTANTS_DIGITAL_ONE.equals(this.getIsVirtual())) return;
		if (BigDecimal.ZERO.compareTo(this.getPublicSize()) >= 0
				|| BigDecimal.ZERO.compareTo(this.getInnerSize()) >= 0
				|| BigDecimal.ZERO.compareTo(this.getBuildSize()) >= 0) {
			throw new BusinessException("house:house_size_smaller_than_zero_exception",
					BusinessException.WARNING);
		}

		if (this.getBuildSize().compareTo(this.getInnerSize()) <= 0) {
			throw new BusinessException("house:house_publicsize_innersize_exception",
					BusinessException.WARNING);
		}
	}
}
